//
//  BaseTableViewController.m
//  ICrEAM
//
//  Created by FoREVer_SaD on 16/10/25.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "BaseTableViewController.h"
#import "MBProgressHUD.h"

@interface BaseTableViewController ()

@property (nonatomic, strong) MBProgressHUD *hud;

@end

@implementation BaseTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.hud = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:self.hud];
    
    UITapGestureRecognizer *cancellTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapView:)];
    [self.hud addGestureRecognizer:cancellTap];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return 0;
}

- (void)tapView:(id)sender
{
    [self.hud hide:YES];
}

- (void)showString:(NSString *)text forSeconds:(NSTimeInterval)seconds
{
    if (self.hud) {
        self.hud.mode = MBProgressHUDModeText;
        self.hud.labelText = text;
        self.hud.userInteractionEnabled = NO;
        [self.hud show:YES];
        [self.view bringSubviewToFront:self.hud];
        [self hideHudAfterSeconds:seconds];
    }
    else {
        self.hud = [[MBProgressHUD alloc] initWithView:self.view];
        [self.view addSubview:self.hud];
        self.hud.mode = MBProgressHUDModeText;
        self.hud.userInteractionEnabled = NO;
        self.hud.labelText = text;
        [self.hud show:YES];
        [self hideHudAfterSeconds:seconds];
    }
}

- (void)showHudWithString:(NSString *)text forSeconds:(NSTimeInterval)seconds
{
    [self showHudWithString:text];
    [self hideHudAfterSeconds:seconds];
}

- (void)showHudWithString:(NSString *)text
{
    if (self.hud) {
        self.hud.labelText = text;
        self.hud.mode = MBProgressHUDModeIndeterminate;
        [self.hud show:YES];
        [self.view bringSubviewToFront:self.hud];
    }
    else {
        self.hud = [[MBProgressHUD alloc] initWithView:self.view];
        self.hud.mode = MBProgressHUDModeIndeterminate;
        [self.view addSubview:self.hud];
        self.hud.labelText = text;
        [self.hud show:YES];
        [self.view bringSubviewToFront:self.hud];
    }
}

- (void)hideHud
{
    [self.hud hide:YES];
}

- (void)hideHudAfterSeconds:(NSTimeInterval)interval
{
    [self.hud hide:YES afterDelay:interval];
}

@end
